package com.bless.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bless.common.core.controller.BaseController;
import com.bless.common.core.domain.AjaxResult;
import com.bless.system.domain.SysFileSource;
import com.bless.system.service.ISysFileSourceService;
import com.bless.common.utils.poi.ExcelUtil;
import com.bless.common.core.page.TableDataInfo;

/**
 * 资源Controller
 *
 * @author bless
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/system/sourceType")
public class SysFileSourceController extends BaseController {
    @Autowired
    private ISysFileSourceService sysFileSourceService;

    /**
     * 查询资源列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysFileSource sysFileSource) {
        startPage();
        List<SysFileSource> list = sysFileSourceService.selectSysFileSourceList(sysFileSource);
        return getDataTable(list);
    }

    /**
     * 导出资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:sourceType:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFileSource sysFileSource) {
        List<SysFileSource> list = sysFileSourceService.selectSysFileSourceList(sysFileSource);
        ExcelUtil<SysFileSource> util = new ExcelUtil<SysFileSource>(SysFileSource.class);
        util.exportExcel(response, list, "资源数据");
    }

    /**
     * 获取资源详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysFileSourceService.selectSysFileSourceById(id));
    }

    /**
     * 新增资源
     */
    @PreAuthorize("@ss.hasPermi('system:sourceType:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SysFileSource sysFileSource) {
        return toAjax(sysFileSourceService.insertSysFileSource(sysFileSource));
    }

    /**
     * 修改资源
     */
    @PreAuthorize("@ss.hasPermi('system:sourceType:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SysFileSource sysFileSource) {
        return toAjax(sysFileSourceService.updateSysFileSource(sysFileSource));
    }

    /**
     * 删除资源
     */
    @PreAuthorize("@ss.hasPermi('system:sourceType:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysFileSourceService.deleteSysFileSourceByIds(ids));
    }
}
